package com.jxw.launcher;

import android.content.Context;
import android.graphics.Canvas;
import android.os.Build;
import android.support.v4.view.MotionEventCompat;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.Scroller;
import java.util.ArrayList;

/* loaded from: classes.dex */
public class PagedView extends ViewGroup {
    protected static final float ALPHA_QUANTIZE_LEVEL = 1.0E-4f;
    static final int AUTOMATIC_PAGE_SPACING = -1;
    private static float CAMERA_DISTANCE = 6500.0f;
    private static final int FLING_THRESHOLD_VELOCITY = 500;
    protected static final int INVALID_PAGE = -1;
    protected static final int INVALID_POINTER = -1;
    private static final int MIN_FLING_VELOCITY = 250;
    private static final int MIN_LENGTH_FOR_FLING = 25;
    private static final int MIN_SNAP_VELOCITY = 1500;
    protected static final float NANOTIME_DIV = 1.0E9f;
    private static final float OVERSCROLL_ACCELERATE_FACTOR = 2.0f;
    protected static final int PAGE_SNAP_ANIMATION_DURATION = 550;
    private static final boolean PERFORM_OVERSCROLL_ROTATION = true;
    private static final float RETURN_TO_ORIGINAL_PAGE_THRESHOLD = 0.33f;
    private static final int SCREEN_SCROLLED_MIN_VERSION = 11;
    private static final float SIGNIFICANT_MOVE_THRESHOLD = 0.4f;
    protected static final int SLOW_PAGE_SNAP_ANIMATION_DURATION = 950;
    protected static final int TOUCH_STATE_NEXT_PAGE = 3;
    protected static final int TOUCH_STATE_PREV_PAGE = 2;
    protected static final int TOUCH_STATE_REST = 0;
    protected static final int TOUCH_STATE_SCROLLING = 1;
    private static float TRANSITION_MAX_ROTATION = 22.0f;
    private static float TRANSITION_PIVOT = 0.0f;
    private static float TRANSITION_SCALE_FACTOR = 0.74f;
    protected int mActivePointerId;
    protected boolean mAllowOverScroll;
    private AccelerateInterpolator mAlphaInterpolator;
    protected int mCellCountX;
    protected int mCellCountY;
    protected boolean mCenterPagesVertically;
    private int[] mChildOffsets;
    private int[] mChildOffsetsWithLayoutScale;
    private int[] mChildRelativeOffsets;
    protected boolean mContentIsRefreshable;
    protected int mCurrentPage;
    protected boolean mDeferScrollUpdate;
    protected float mDensity;
    protected ArrayList<Boolean> mDirtyPageContent;
    private float mDownMotionX;
    protected boolean mFadeInAdjacentScreens;
    protected boolean mFirstLayout;
    protected int mFlingThresholdVelocity;
    protected boolean mForceDrawAllChildrenNextFrame;
    protected boolean mForceScreenScrolled;
    protected boolean mHapticCaptureFling;
    protected boolean mHapticFlingStarted;
    protected boolean mIsDataReady;
    protected boolean mIsPageMoving;
    protected int mLastHapticScreen;
    protected float mLastMotionX;
    protected float mLastMotionXRemainder;
    protected float mLastMotionY;
    private int mLastScreenCenter;
    protected float mLayoutScale;
    private DecelerateInterpolator mLeftScreenAlphaInterpolator;
    protected int mMaxScrollX;
    private int mMaximumVelocity;
    protected int mMinFlingVelocity;
    protected int mMinSnapVelocity;
    protected int mNextPage;
    protected int mOverScrollX;
    protected int mPageLayoutHeightGap;
    protected int mPageLayoutPaddingBottom;
    protected int mPageLayoutPaddingLeft;
    protected int mPageLayoutPaddingRight;
    protected int mPageLayoutPaddingTop;
    protected int mPageLayoutWidthGap;
    protected int mPageSpacing;
    private int mPagingTouchSlop;
    protected Scroller mScroller;
    protected float mSmoothingTime;
    protected int[] mTempVisiblePagesRange;
    protected float mTotalMotionX;
    protected int mTouchSlop;
    protected int mTouchState;
    protected float mTouchX;
    protected int mUnboundedScrollX;
    protected boolean mUsePagingTouchSlop;
    private VelocityTracker mVelocityTracker;
    ZInterpolator mZInterpolator;
    private OnScreenChangeListener onScreenChangeListener;
    private OnScreenChangeListenerDataLoad onScreenChangeListenerDataLoad;

    /* loaded from: classes.dex */
    public interface OnScreenChangeListener {
        void onScreenChange(int i);
    }

    /* loaded from: classes.dex */
    public interface OnScreenChangeListenerDataLoad {
        void onScreenChange(Boolean bool);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class ScrollInterpolator implements Interpolator {
        @Override // android.animation.TimeInterpolator
        public float getInterpolation(float f) {
            float f2 = f - 1.0f;
            return (f2 * f2 * f2 * f2 * f2) + 1.0f;
        }
    }

    /* loaded from: classes.dex */
    public interface TimeInterpolator {
        float getInterpolation(float f);
    }

    public PagedView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.mAlphaInterpolator = new AccelerateInterpolator(0.9f);
        this.mLeftScreenAlphaInterpolator = new DecelerateInterpolator(4.0f);
        this.mFirstLayout = true;
        this.mNextPage = -1;
        this.mLastScreenCenter = -1;
        this.mTouchState = 0;
        this.mForceScreenScrolled = false;
        this.mCellCountX = 0;
        this.mCellCountY = 0;
        this.mAllowOverScroll = true;
        this.mTempVisiblePagesRange = new int[2];
        this.mLayoutScale = 1.0f;
        this.mActivePointerId = -1;
        this.mContentIsRefreshable = true;
        this.mFadeInAdjacentScreens = true;
        this.mUsePagingTouchSlop = true;
        this.mDeferScrollUpdate = false;
        this.mIsPageMoving = false;
        this.mIsDataReady = false;
        this.mHapticFlingStarted = false;
        this.mHapticCaptureFling = true;
        this.mLastHapticScreen = 0;
        this.mZInterpolator = new ZInterpolator(0.5f);
        init();
    }

    public PagedView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public PagedView(Context context) {
        this(context, null);
    }

    @Override // android.view.View
    protected void onMeasure(int i, int i2) {
        int mode = View.MeasureSpec.getMode(i);
        int size = View.MeasureSpec.getSize(i);
        int mode2 = View.MeasureSpec.getMode(i2);
        int size2 = View.MeasureSpec.getSize(i2);
        if (mode != 1073741824) {
            throw new IllegalStateException("Workspace can only be used in EXACTLY mode.");
        }
        if (size <= 0 || size2 <= 0) {
            super.onMeasure(i, i2);
            return;
        }
        int paddingTop = getPaddingTop() + getPaddingBottom();
        int paddingLeft = getPaddingLeft() + getPaddingRight();
        int childCount = getChildCount();
        int i3 = 0;
        int i4 = 0;
        while (true) {
            int i5 = Integer.MIN_VALUE;
            if (i3 >= childCount) {
                break;
            }
            View pageAt = getPageAt(i3);
            ViewGroup.LayoutParams layoutParams = pageAt.getLayoutParams();
            int i6 = layoutParams.width == -2 ? Integer.MIN_VALUE : 1073741824;
            if (layoutParams.height != -2) {
                i5 = 1073741824;
            }
            pageAt.measure(View.MeasureSpec.makeMeasureSpec(size - paddingLeft, i6), View.MeasureSpec.makeMeasureSpec(size2 - paddingTop, i5));
            i4 = Math.max(i4, pageAt.getMeasuredHeight());
            i3++;
        }
        if (mode2 == Integer.MIN_VALUE) {
            size2 = i4 + paddingTop;
        }
        setMeasuredDimension(size, size2);
        invalidateCachedOffsets();
        if (childCount > 0 && this.mPageSpacing == -1) {
            int relativeChildOffset = getRelativeChildOffset(0);
            setPageSpacing(Math.max(relativeChildOffset, (size - relativeChildOffset) - getChildAt(0).getMeasuredWidth()));
        }
        if (childCount > 0) {
            int i7 = childCount - 1;
            this.mMaxScrollX = getChildOffset(i7) - getRelativeChildOffset(i7);
            return;
        }
        this.mMaxScrollX = 0;
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
        int i5;
        int paddingTop = getPaddingTop() + getPaddingBottom();
        int childCount = getChildCount();
        int relativeChildOffset = getRelativeChildOffset(0);
        for (int i6 = 0; i6 < childCount; i6++) {
            View pageAt = getPageAt(i6);
            if (pageAt.getVisibility() != 8) {
                int scaledMeasuredWidth = getScaledMeasuredWidth(pageAt);
                int measuredHeight = pageAt.getMeasuredHeight();
                int paddingTop2 = getPaddingTop();
                if (this.mCenterPagesVertically) {
                    paddingTop2 += ((getMeasuredHeight() - paddingTop) - measuredHeight) / 2;
                }
                pageAt.layout(relativeChildOffset, paddingTop2, pageAt.getMeasuredWidth() + relativeChildOffset, measuredHeight + paddingTop2);
                relativeChildOffset += scaledMeasuredWidth + this.mPageSpacing;
            }
        }
        if (!this.mFirstLayout || (i5 = this.mCurrentPage) < 0 || i5 >= getChildCount()) {
            return;
        }
        updateCurrentPageScroll();
        this.mFirstLayout = false;
    }

    View getPageAt(int i) {
        return getChildAt(i);
    }

    public int getmCurrentPage() {
        return this.mCurrentPage;
    }

    protected int getChildWidth(int i) {
        return getPageAt(i).getMeasuredWidth();
    }

    protected int getScaledMeasuredWidth(View view) {
        int measuredWidth = view.getMeasuredWidth();
        if (measuredWidth < 0) {
            measuredWidth = 0;
        }
        return (int) ((measuredWidth * this.mLayoutScale) + 0.5f);
    }

    protected void updateCurrentPageScroll() {
        int childOffset = getChildOffset(this.mCurrentPage) - getRelativeChildOffset(this.mCurrentPage);
        scrollTo(childOffset, 0);
        this.mScroller.setFinalX(childOffset);
        this.mScroller.forceFinished(true);
    }

    protected int getChildOffset(int i) {
        int[] iArr = Float.compare(this.mLayoutScale, 1.0f) == 0 ? this.mChildOffsets : this.mChildOffsetsWithLayoutScale;
        if (iArr != null && iArr[i] != -1) {
            return iArr[i];
        }
        if (getChildCount() == 0) {
            return 0;
        }
        int relativeChildOffset = getRelativeChildOffset(0);
        for (int i2 = 0; i2 < i; i2++) {
            relativeChildOffset += getScaledMeasuredWidth(getPageAt(i2)) + this.mPageSpacing;
        }
        if (iArr != null) {
            iArr[i] = relativeChildOffset;
        }
        return relativeChildOffset;
    }

    protected int getRelativeChildOffset(int i) {
        int[] iArr = this.mChildRelativeOffsets;
        if (iArr != null && iArr[i] != -1) {
            return iArr[i];
        }
        int paddingLeft = getPaddingLeft() + (((getMeasuredWidth() - (getPaddingLeft() + getPaddingRight())) - getChildWidth(i)) / 2);
        int[] iArr2 = this.mChildRelativeOffsets;
        if (iArr2 != null) {
            iArr2[i] = paddingLeft;
        }
        return paddingLeft;
    }

    public void setPageSpacing(int i) {
        this.mPageSpacing = i;
        invalidateCachedOffsets();
    }

    protected void invalidateCachedOffsets() {
        int childCount = getChildCount();
        if (childCount == 0) {
            this.mChildOffsets = null;
            this.mChildRelativeOffsets = null;
            this.mChildOffsetsWithLayoutScale = null;
            return;
        }
        this.mChildOffsets = new int[childCount];
        this.mChildRelativeOffsets = new int[childCount];
        this.mChildOffsetsWithLayoutScale = new int[childCount];
        for (int i = 0; i < childCount; i++) {
            this.mChildOffsets[i] = -1;
            this.mChildRelativeOffsets[i] = -1;
            this.mChildOffsetsWithLayoutScale[i] = -1;
        }
    }

    protected void init() {
        this.mDirtyPageContent = new ArrayList<>();
        this.mDirtyPageContent.ensureCapacity(32);
        this.mScroller = new Scroller(getContext(), new ScrollInterpolator());
        this.mCurrentPage = 1;
        this.mCenterPagesVertically = true;
        ViewConfiguration viewConfiguration = ViewConfiguration.get(getContext());
        this.mTouchSlop = viewConfiguration.getScaledTouchSlop();
        this.mPagingTouchSlop = viewConfiguration.getScaledPagingTouchSlop();
        this.mMaximumVelocity = viewConfiguration.getScaledMaximumFlingVelocity();
        this.mDensity = getResources().getDisplayMetrics().density;
        float f = this.mDensity;
        this.mFlingThresholdVelocity = (int) (500.0f * f);
        this.mMinFlingVelocity = (int) (250.0f * f);
        this.mMinSnapVelocity = (int) (f * 1500.0f);
    }

    /* JADX WARN: Removed duplicated region for block: B:49:0x00ae A[ORIG_RETURN, RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:51:? A[RETURN, SYNTHETIC] */
    @Override // android.view.ViewGroup
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public boolean onInterceptTouchEvent(android.view.MotionEvent r8) {
        /*
            r7 = this;
            r7.acquireVelocityTrackerAndAddMovement(r8)
            int r0 = r7.getChildCount()
            if (r0 > 0) goto Le
            boolean r8 = super.onInterceptTouchEvent(r8)
            return r8
        Le:
            int r0 = r8.getAction()
            r1 = 2
            r2 = 1
            if (r0 != r1) goto L1b
            int r3 = r7.mTouchState
            if (r3 != r2) goto L1b
            return r2
        L1b:
            r0 = r0 & 255(0xff, float:3.57E-43)
            r3 = 3
            r4 = 0
            if (r0 == 0) goto L46
            r5 = -1
            if (r0 == r2) goto L3e
            if (r0 == r1) goto L35
            if (r0 == r3) goto L3e
            r1 = 6
            if (r0 == r1) goto L2d
            goto La9
        L2d:
            r7.onSecondaryPointerUp(r8)
            r7.releaseVelocityTracker()
            goto La9
        L35:
            int r0 = r7.mActivePointerId
            if (r0 == r5) goto L46
            r7.determineScrollingStart(r8)
            goto La9
        L3e:
            r7.mTouchState = r4
            r7.mActivePointerId = r5
            r7.releaseVelocityTracker()
            goto La9
        L46:
            float r0 = r8.getX()
            float r5 = r8.getY()
            r7.mDownMotionX = r0
            r7.mLastMotionX = r0
            r7.mLastMotionY = r5
            r6 = 0
            r7.mLastMotionXRemainder = r6
            r7.mTotalMotionX = r6
            int r8 = r8.getPointerId(r4)
            r7.mActivePointerId = r8
            android.widget.Scroller r8 = r7.mScroller
            int r8 = r8.getFinalX()
            android.widget.Scroller r6 = r7.mScroller
            int r6 = r6.getCurrX()
            int r8 = r8 - r6
            int r8 = java.lang.Math.abs(r8)
            android.widget.Scroller r6 = r7.mScroller
            boolean r6 = r6.isFinished()
            if (r6 != 0) goto L7f
            int r6 = r7.mTouchSlop
            if (r8 >= r6) goto L7d
            goto L7f
        L7d:
            r8 = 0
            goto L80
        L7f:
            r8 = 1
        L80:
            if (r8 == 0) goto L8a
            r7.mTouchState = r4
            android.widget.Scroller r8 = r7.mScroller
            r8.abortAnimation()
            goto L8c
        L8a:
            r7.mTouchState = r2
        L8c:
            int r8 = r7.mTouchState
            if (r8 == r1) goto La9
            if (r8 == r3) goto La9
            int r8 = r7.getChildCount()
            if (r8 <= 0) goto La9
            boolean r8 = r7.hitsPreviousPage(r0, r5)
            if (r8 == 0) goto La1
            r7.mTouchState = r1
            goto La9
        La1:
            boolean r8 = r7.hitsNextPage(r0, r5)
            if (r8 == 0) goto La9
            r7.mTouchState = r3
        La9:
            int r8 = r7.mTouchState
            if (r8 == 0) goto Lae
            goto Laf
        Lae:
            r2 = 0
        Laf:
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: com.jxw.launcher.PagedView.onInterceptTouchEvent(android.view.MotionEvent):boolean");
    }

    protected boolean hitsPreviousPage(float f, float f2) {
        return f < ((float) (getRelativeChildOffset(this.mCurrentPage) - this.mPageSpacing));
    }

    protected boolean hitsNextPage(float f, float f2) {
        return f > ((float) ((getMeasuredWidth() - getRelativeChildOffset(this.mCurrentPage)) + this.mPageSpacing));
    }

    @Override // android.view.View
    public boolean onTouchEvent(MotionEvent motionEvent) {
        int i;
        if (getChildCount() <= 0) {
            return super.onTouchEvent(motionEvent);
        }
        acquireVelocityTrackerAndAddMovement(motionEvent);
        int action = motionEvent.getAction() & 255;
        if (action == 0) {
            if (!this.mScroller.isFinished()) {
                this.mScroller.abortAnimation();
            }
            float x = motionEvent.getX();
            this.mLastMotionX = x;
            this.mDownMotionX = x;
            this.mLastMotionXRemainder = 0.0f;
            this.mTotalMotionX = 0.0f;
            this.mActivePointerId = motionEvent.getPointerId(0);
            if (this.mTouchState == 1) {
                pageBeginMoving();
            }
        } else if (action == 1) {
            int i2 = this.mTouchState;
            if (i2 == 1) {
                int i3 = this.mActivePointerId;
                float x2 = motionEvent.getX(motionEvent.findPointerIndex(i3));
                VelocityTracker velocityTracker = this.mVelocityTracker;
                velocityTracker.computeCurrentVelocity(1000, this.mMaximumVelocity);
                int xVelocity = (int) velocityTracker.getXVelocity(i3);
                int i4 = (int) (x2 - this.mDownMotionX);
                float scaledMeasuredWidth = getScaledMeasuredWidth(getPageAt(this.mCurrentPage));
                boolean z = ((float) Math.abs(i4)) > SIGNIFICANT_MOVE_THRESHOLD * scaledMeasuredWidth;
                this.mTotalMotionX += Math.abs((this.mLastMotionX + this.mLastMotionXRemainder) - x2);
                boolean z2 = this.mTotalMotionX > 25.0f && Math.abs(xVelocity) > this.mFlingThresholdVelocity;
                boolean z3 = ((float) Math.abs(i4)) > scaledMeasuredWidth * RETURN_TO_ORIGINAL_PAGE_THRESHOLD && Math.signum((float) xVelocity) != Math.signum((float) i4) && z2;
                if (((z && i4 > 0 && !z2) || (z2 && xVelocity > 0)) && (i = this.mCurrentPage) > 0) {
                    if (!z3) {
                        i--;
                    }
                    snapToPageWithVelocity(i, xVelocity);
                } else if (((z && i4 < 0 && !z2) || (z2 && xVelocity < 0)) && this.mCurrentPage < getChildCount() - 1) {
                    int i5 = this.mCurrentPage;
                    if (!z3) {
                        i5++;
                    }
                    snapToPageWithVelocity(i5, xVelocity);
                } else {
                    snapToDestination();
                }
            } else if (i2 == 2) {
                int max = Math.max(0, this.mCurrentPage - 1);
                if (max != this.mCurrentPage) {
                    snapToPage(max);
                } else {
                    snapToDestination();
                }
            } else if (i2 == 3) {
                int min = Math.min(getChildCount() - 1, this.mCurrentPage + 1);
                if (min != this.mCurrentPage) {
                    snapToPage(min);
                } else {
                    snapToDestination();
                }
            }
            this.mTouchState = 0;
            this.mActivePointerId = -1;
            releaseVelocityTracker();
        } else if (action != 2) {
            if (action == 3) {
                if (this.mTouchState == 1) {
                    snapToDestination();
                }
                this.mTouchState = 0;
                this.mActivePointerId = -1;
                releaseVelocityTracker();
            } else if (action == 6) {
                onSecondaryPointerUp(motionEvent);
            }
        } else if (this.mTouchState == 1) {
            float x3 = motionEvent.getX(motionEvent.findPointerIndex(this.mActivePointerId));
            float f = (this.mLastMotionX + this.mLastMotionXRemainder) - x3;
            this.mTotalMotionX += Math.abs(f);
            if (Math.abs(f) >= 1.0f) {
                this.mTouchX += f;
                this.mSmoothingTime = ((float) System.nanoTime()) / NANOTIME_DIV;
                if (!this.mDeferScrollUpdate) {
                    scrollBy((int) f, 0);
                } else {
                    invalidate();
                }
                this.mLastMotionX = x3;
                this.mLastMotionXRemainder = f - ((int) f);
            } else {
                awakenScrollBars();
            }
        } else {
            determineScrollingStart(motionEvent);
        }
        return true;
    }

    @Override // android.view.View
    public boolean onGenericMotionEvent(MotionEvent motionEvent) {
        float f;
        float axisValue;
        if (motionEvent.getSource() != 0 && motionEvent.getAction() == 8) {
            if ((motionEvent.getMetaState() & 1) != 0) {
                axisValue = motionEvent.getAxisValue(9);
                f = 0.0f;
            } else {
                f = -motionEvent.getAxisValue(9);
                axisValue = motionEvent.getAxisValue(10);
            }
            if (axisValue != 0.0f || f != 0.0f) {
                if (axisValue > 0.0f || f > 0.0f) {
                    scrollRight();
                } else {
                    scrollLeft();
                }
                return true;
            }
        }
        return super.onGenericMotionEvent(motionEvent);
    }

    private void acquireVelocityTrackerAndAddMovement(MotionEvent motionEvent) {
        if (this.mVelocityTracker == null) {
            this.mVelocityTracker = VelocityTracker.obtain();
        }
        this.mVelocityTracker.addMovement(motionEvent);
    }

    private void releaseVelocityTracker() {
        VelocityTracker velocityTracker = this.mVelocityTracker;
        if (velocityTracker != null) {
            velocityTracker.recycle();
            this.mVelocityTracker = null;
        }
    }

    protected void pageBeginMoving() {
        if (this.mIsPageMoving) {
            return;
        }
        this.mIsPageMoving = true;
        onPageBeginMoving();
        OnScreenChangeListenerDataLoad onScreenChangeListenerDataLoad = this.onScreenChangeListenerDataLoad;
        if (onScreenChangeListenerDataLoad != null) {
            onScreenChangeListenerDataLoad.onScreenChange(Boolean.valueOf(this.mIsPageMoving));
        }
    }

    protected void pageEndMoving() {
        if (this.mIsPageMoving) {
            this.mIsPageMoving = false;
            onPageEndMoving();
            OnScreenChangeListenerDataLoad onScreenChangeListenerDataLoad = this.onScreenChangeListenerDataLoad;
            if (onScreenChangeListenerDataLoad != null) {
                onScreenChangeListenerDataLoad.onScreenChange(Boolean.valueOf(this.mIsPageMoving));
            }
        }
    }

    protected boolean isPageMoving() {
        return this.mIsPageMoving;
    }

    protected void onPageBeginMoving() {
        int i;
        int i2;
        if (!this.mHapticCaptureFling || (i = this.mNextPage) == (i2 = this.mCurrentPage)) {
            return;
        }
        if (!this.mHapticFlingStarted) {
            this.mHapticFlingStarted = true;
            this.mLastHapticScreen = i2;
            return;
        }
        if (i != -1) {
            int i3 = this.mLastHapticScreen;
        }
        this.mHapticFlingStarted = false;
    }

    protected void onPageEndMoving() {
        this.mHapticCaptureFling = true;
        this.mHapticFlingStarted = false;
        this.mForceDrawAllChildrenNextFrame = true;
    }

    protected void determineScrollingStart(MotionEvent motionEvent) {
        determineScrollingStart(motionEvent, 1.0f);
    }

    protected void determineScrollingStart(MotionEvent motionEvent, float f) {
        int findPointerIndex = motionEvent.findPointerIndex(this.mActivePointerId);
        if (findPointerIndex == -1) {
            return;
        }
        float x = motionEvent.getX(findPointerIndex);
        float y = motionEvent.getY(findPointerIndex);
        int abs = (int) Math.abs(x - this.mLastMotionX);
        int abs2 = (int) Math.abs(y - this.mLastMotionY);
        int round = Math.round(f * this.mTouchSlop);
        boolean z = abs > this.mPagingTouchSlop;
        boolean z2 = abs > round;
        boolean z3 = abs2 > round;
        if (z2 || z || z3) {
            if (this.mUsePagingTouchSlop) {
                if (!z) {
                    return;
                }
            } else if (!z2) {
                return;
            }
            this.mTouchState = 1;
            this.mTotalMotionX += Math.abs(this.mLastMotionX - x);
            this.mLastMotionX = x;
            this.mLastMotionXRemainder = 0.0f;
            this.mTouchX = getScrollX();
            this.mSmoothingTime = ((float) System.nanoTime()) / NANOTIME_DIV;
            pageBeginMoving();
        }
    }

    protected void snapToPageWithVelocity(int i, int i2) {
        int max = Math.max(0, Math.min(i, getChildCount() - 1));
        int measuredWidth = getMeasuredWidth() / 2;
        int childOffset = (getChildOffset(max) - getRelativeChildOffset(max)) - this.mUnboundedScrollX;
        if (Math.abs(i2) < this.mMinFlingVelocity) {
            snapToPage(max, 550);
            return;
        }
        float f = measuredWidth;
        snapToPage(max, childOffset, Math.round(Math.abs((f + (distanceInfluenceForSnapDuration(Math.min(1.0f, (Math.abs(childOffset) * 1.0f) / (measuredWidth * 2))) * f)) / Math.max(this.mMinSnapVelocity, Math.abs(i2))) * 1000.0f) * 4);
    }

    public void snapToPage(int i) {
        snapToPage(i, 550);
    }

    protected void snapToPage(int i, int i2) {
        int max = Math.max(0, Math.min(i, getPageCount() - 1));
        snapToPage(max, (getChildOffset(max) - getRelativeChildOffset(max)) - this.mUnboundedScrollX, i2);
    }

    protected void snapToPage(int i, int i2, int i3) {
        int i4;
        this.mNextPage = i;
        OnScreenChangeListener onScreenChangeListener = this.onScreenChangeListener;
        if (onScreenChangeListener != null) {
            onScreenChangeListener.onScreenChange(this.mNextPage);
        }
        View focusedChild = getFocusedChild();
        if (focusedChild != null && i != (i4 = this.mCurrentPage) && focusedChild == getPageAt(i4)) {
            focusedChild.clearFocus();
        }
        pageBeginMoving();
        awakenScrollBars(i3);
        if (i3 == 0) {
            i3 = Math.abs(i2);
        }
        int i5 = i3;
        if (!this.mScroller.isFinished()) {
            this.mScroller.abortAnimation();
        }
        this.mScroller.startScroll(this.mUnboundedScrollX, 0, i2, 0, i5);
        invalidate();
    }

    public void scrollLeft() {
        if (this.mScroller.isFinished()) {
            int i = this.mCurrentPage;
            if (i > 0) {
                snapToPage(i - 1);
                return;
            }
            return;
        }
        int i2 = this.mNextPage;
        if (i2 > 0) {
            snapToPage(i2 - 1);
        }
    }

    public void scrollRight() {
        if (this.mScroller.isFinished()) {
            if (this.mCurrentPage < getChildCount() - 1) {
                snapToPage(this.mCurrentPage + 1);
            }
        } else if (this.mNextPage < getChildCount() - 1) {
            snapToPage(this.mNextPage + 1);
        }
    }

    protected void snapToDestination() {
        snapToPage(getPageNearestToCenterOfScreen(), 550);
    }

    private void onSecondaryPointerUp(MotionEvent motionEvent) {
        int action = (motionEvent.getAction() & MotionEventCompat.ACTION_POINTER_INDEX_MASK) >> 8;
        if (motionEvent.getPointerId(action) == this.mActivePointerId) {
            int i = action == 0 ? 1 : 0;
            float x = motionEvent.getX(i);
            this.mDownMotionX = x;
            this.mLastMotionX = x;
            this.mLastMotionY = motionEvent.getY(i);
            this.mLastMotionXRemainder = 0.0f;
            this.mActivePointerId = motionEvent.getPointerId(i);
            VelocityTracker velocityTracker = this.mVelocityTracker;
            if (velocityTracker != null) {
                velocityTracker.clear();
            }
        }
    }

    float distanceInfluenceForSnapDuration(float f) {
        double d;
        Double.isNaN(f - 0.5f);
        return (float) Math.sin((float) (d * 0.4712389167638204d));
    }

    protected int getPageCount() {
        return getChildCount();
    }

    protected int getPageNearestToCenterOfScreen() {
        int scrollX = getScrollX() + (getMeasuredWidth() / 2);
        int childCount = getChildCount();
        int i = Integer.MAX_VALUE;
        int i2 = -1;
        for (int i3 = 0; i3 < childCount; i3++) {
            int abs = Math.abs((getChildOffset(i3) + (getScaledMeasuredWidth(getPageAt(i3)) / 2)) - scrollX);
            if (abs < i) {
                i2 = i3;
                i = abs;
            }
        }
        return i2;
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void dispatchDraw(Canvas canvas) {
        int measuredWidth = this.mOverScrollX + (getMeasuredWidth() / 2);
        if (measuredWidth != this.mLastScreenCenter || this.mForceScreenScrolled) {
            this.mForceScreenScrolled = false;
            screenScrolled(measuredWidth);
            this.mLastScreenCenter = measuredWidth;
        }
        if (getChildCount() > 0) {
            getVisiblePages(this.mTempVisiblePagesRange);
            int[] iArr = this.mTempVisiblePagesRange;
            int i = iArr[0];
            int i2 = iArr[1];
            if (i == -1 || i2 == -1) {
                return;
            }
            long drawingTime = getDrawingTime();
            canvas.save();
            canvas.clipRect(getScrollX(), getScrollY(), (getScrollX() + getRight()) - getLeft(), (getScrollY() + getBottom()) - getTop());
            for (int childCount = getChildCount() - 1; childCount >= 0; childCount--) {
                View pageAt = getPageAt(childCount);
                if (i <= childCount && childCount <= i2 && shouldDrawChild(pageAt)) {
                    pageAt.setVisibility(0);
                    drawChild(canvas, pageAt, drawingTime);
                } else {
                    pageAt.setVisibility(4);
                }
            }
            this.mForceDrawAllChildrenNextFrame = false;
            canvas.restore();
        }
    }

    protected void screenScrolled(int i) {
        float interpolation;
        for (int i2 = 0; i2 < getChildCount(); i2++) {
            View pageAt = getPageAt(i2);
            if (pageAt != null) {
                float scrollProgress = getScrollProgress(i, pageAt, i2);
                float f = 0.0f;
                float interpolation2 = this.mZInterpolator.getInterpolation(Math.abs(Math.min(scrollProgress, 0.0f)));
                float f2 = 1.0f;
                float f3 = (interpolation2 * TRANSITION_SCALE_FACTOR) + (1.0f - interpolation2);
                float min = Math.min(0.0f, scrollProgress) * pageAt.getMeasuredWidth();
                if (scrollProgress < 0.0f) {
                    interpolation = scrollProgress < 0.0f ? this.mAlphaInterpolator.getInterpolation(1.0f - Math.abs(scrollProgress)) : 1.0f;
                    if (i2 == 0) {
                        setOverScrollAmount(pageAt, Math.abs(scrollProgress));
                    }
                } else {
                    interpolation = this.mLeftScreenAlphaInterpolator.getInterpolation(1.0f - scrollProgress);
                    if (i2 == getChildCount() - 1) {
                        setOverScrollAmount(pageAt, Math.abs(scrollProgress));
                    }
                }
                int measuredWidth = pageAt.getMeasuredWidth();
                int measuredHeight = pageAt.getMeasuredHeight();
                if (getVersion() >= 11) {
                    pageAt.setCameraDistance(this.mDensity * CAMERA_DISTANCE);
                    if (i2 == 0 && scrollProgress < 0.0f) {
                        pageAt.setPivotX(TRANSITION_PIVOT * measuredWidth);
                        pageAt.setRotationY((-TRANSITION_MAX_ROTATION) * scrollProgress);
                    } else if (i2 == getChildCount() - 1 && scrollProgress > 0.0f) {
                        pageAt.setPivotX((1.0f - TRANSITION_PIVOT) * measuredWidth);
                        pageAt.setRotationY((-TRANSITION_MAX_ROTATION) * scrollProgress);
                    } else {
                        pageAt.setPivotY(measuredHeight / 2.0f);
                        pageAt.setPivotX(measuredWidth / 2.0f);
                        pageAt.setRotationY(0.0f);
                        f2 = f3;
                        f = min;
                        pageAt.setTranslationX(f);
                        pageAt.setScaleX(f2);
                        pageAt.setScaleY(f2);
                        pageAt.setAlpha(interpolation);
                    }
                    interpolation = 1.0f;
                    pageAt.setTranslationX(f);
                    pageAt.setScaleX(f2);
                    pageAt.setScaleY(f2);
                    pageAt.setAlpha(interpolation);
                }
                if (interpolation < 0.3d) {
                    pageAt.setVisibility(8);
                } else if (pageAt.getVisibility() != 0) {
                    pageAt.setVisibility(0);
                }
                Log.d("Nevin", "VERSION:" + getVersion());
            }
        }
    }

    public int getVersion() {
        try {
            return Build.VERSION.SDK_INT;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    protected void setOverScrollAmount(View view, float f) {
        Math.round(f * 255.0f);
        view.invalidate();
    }

    protected void getVisiblePages(int[] iArr) {
        int i;
        int childCount = getChildCount();
        if (childCount > 0) {
            int measuredWidth = getMeasuredWidth();
            View pageAt = getPageAt(0);
            int i2 = 0;
            while (true) {
                i = childCount - 1;
                if (i2 >= i || (pageAt.getLeft() + pageAt.getWidth()) - pageAt.getPaddingRight() >= getScrollX()) {
                    break;
                }
                i2++;
                pageAt = getPageAt(i2);
            }
            View pageAt2 = getPageAt(i2 + 1);
            int i3 = i2;
            while (i3 < i && pageAt2.getLeft() - pageAt2.getPaddingLeft() < getScrollX() + measuredWidth) {
                i3++;
                pageAt2 = getPageAt(i3 + 1);
            }
            iArr[0] = i2;
            iArr[1] = i3;
            return;
        }
        iArr[0] = -1;
        iArr[1] = -1;
    }

    protected boolean shouldDrawChild(View view) {
        return getVersion() < 11 || ((double) view.getAlpha()) > 0.15d;
    }

    protected float getScrollProgress(int i, View view, int i2) {
        int scaledMeasuredWidth = getScaledMeasuredWidth(view) + this.mPageSpacing;
        return Math.max(Math.min((i - ((getChildOffset(i2) - getRelativeChildOffset(i2)) + (getMeasuredWidth() / 2))) / (scaledMeasuredWidth * 1.0f), 1.0f), -1.0f);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class ZInterpolator implements TimeInterpolator {
        private float focalLength;

        public ZInterpolator(float f) {
            this.focalLength = f;
        }

        @Override // com.jxw.launcher.PagedView.TimeInterpolator
        public float getInterpolation(float f) {
            float f2 = this.focalLength;
            return (1.0f - (f2 / (f + f2))) / (1.0f - (f2 / (f2 + 1.0f)));
        }
    }

    @Override // android.view.View
    public void scrollBy(int i, int i2) {
        scrollTo(this.mUnboundedScrollX + i, getScrollY() + i2);
    }

    @Override // android.view.View
    public void scrollTo(int i, int i2) {
        this.mUnboundedScrollX = i;
        if (i < 0) {
            super.scrollTo(0, i2);
            if (this.mAllowOverScroll) {
                overScroll(i);
            }
        } else {
            int i3 = this.mMaxScrollX;
            if (i > i3) {
                super.scrollTo(i3, i2);
                if (this.mAllowOverScroll) {
                    overScroll(i - this.mMaxScrollX);
                }
            } else {
                this.mOverScrollX = i;
                super.scrollTo(i, i2);
            }
        }
        this.mTouchX = i;
        this.mSmoothingTime = ((float) System.nanoTime()) / NANOTIME_DIV;
    }

    protected void overScroll(float f) {
        acceleratedOverScroll(f);
    }

    protected void acceleratedOverScroll(float f) {
        float measuredWidth = getMeasuredWidth();
        float f2 = (f / measuredWidth) * 2.0f;
        if (f2 == 0.0f) {
            return;
        }
        if (Math.abs(f2) >= 1.0f) {
            f2 /= Math.abs(f2);
        }
        int round = Math.round(f2 * measuredWidth);
        if (f < 0.0f) {
            this.mOverScrollX = round;
            super.scrollTo(0, getScrollY());
        } else {
            int i = this.mMaxScrollX;
            this.mOverScrollX = round + i;
            super.scrollTo(i, getScrollY());
        }
        invalidate();
    }

    protected boolean computeScrollHelper() {
        if (this.mScroller.computeScrollOffset()) {
            if (getScrollX() != this.mScroller.getCurrX() || getScrollY() != this.mScroller.getCurrY() || this.mOverScrollX != this.mScroller.getCurrX()) {
                scrollTo(this.mScroller.getCurrX(), this.mScroller.getCurrY());
            }
            invalidate();
            return true;
        }
        int i = this.mNextPage;
        if (i != -1) {
            this.mCurrentPage = Math.max(0, Math.min(i, getPageCount() - 1));
            this.mNextPage = -1;
            if (this.mTouchState == 0) {
                pageEndMoving();
            }
            if (((AccessibilityManager) getContext().getSystemService("accessibility")).isEnabled()) {
                sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(4096));
            }
            return true;
        }
        return false;
    }

    @Override // android.view.View
    public void computeScroll() {
        computeScrollHelper();
    }

    public void setOnScreenChangeListener(OnScreenChangeListener onScreenChangeListener) {
        this.onScreenChangeListener = onScreenChangeListener;
    }

    public void setOnScreenChangeListenerDataLoad(OnScreenChangeListenerDataLoad onScreenChangeListenerDataLoad) {
        this.onScreenChangeListenerDataLoad = onScreenChangeListenerDataLoad;
    }
}
